from flask import Flask
from webapp.plugins.celery_app import make_celery
from webapp.extensions import db, redis_store, login_manager
from .config import Config

from webapp.extensions import alembic

flask_app = Flask(__name__)
flask_app.config.from_object(Config)
db.init_app(flask_app)
redis_store.init_app(flask_app, decode_responses=True)
celery = make_celery(flask_app)
alembic.init_app(flask_app)
login_manager.init_app(flask_app)

from .controllers.pic import pic_blueprint
from .controllers.work import work_blueprint
from .controllers.api import api_blueprint
from .controllers.user import user_blueprint
from .controllers.errors import errors_blueprint
from webapp.plugins.functions import site_info

flask_app.add_template_global(site_info, 'siteinfo')
flask_app.register_blueprint(pic_blueprint, url_prefix='/pic')
flask_app.register_blueprint(work_blueprint, url_prefix='/work')
flask_app.register_blueprint(api_blueprint, url_prefix='/api')
flask_app.register_blueprint(user_blueprint, url_prefix='/user')
flask_app.register_blueprint(errors_blueprint)

from webapp.plugins.tasks import *
